package NC61_两数之和;
import java.util.*;


public class Solution {
    /**
     *
     * @param numbers int整型一维数组
     * @param target int整型
     * @return int整型一维数组
     */
    public int[] twoSum (int[] numbers, int target) {
        // write code here
        int n = numbers.length;
        int[] res = new int[2];

        if (numbers.length == 0){
            return res;
        }

        Map<Integer, Integer> map = new HashMap<>();

        for (int i = 0 ; i < n; i++) {
            if (map.containsKey(target - numbers[i])) {
                res[0] = map.get(target - numbers[i]) + 1;
                res[1] = map.get(i) + 1;
            } else {
                map.put(target - numbers[i], i);
            }
        }
        return res;
    }
}